﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MaLu.Common;
using System.Xml;
using MaLu.BusiLogic;
using MaLu.Framework.Common;
using System.Data;
using MaLu.Data;

namespace MaluJg.web.ProjectFund
{
    public partial class Item7v : ProjectPage1
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
        private void BindData()
        {
            string projectname = string.Empty;
            string content = BLProject.GetProjectItem(Provider, ProjectID, "item7.aspx", ref projectname);
            if (content != string.Empty)
            {
                XmlDocument document = new XmlDocument();
                document.LoadXml(content);
                XmlElement xe = document.SelectSingleNode("//施工单位") as XmlElement;
                tbShiGongDept.Text = Util.ReturnXml( xe.InnerText);
                xe = document.SelectSingleNode("//工程名称") as XmlElement;
                tbProjectName.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//通知年") as XmlElement;
                tbYear1.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//通知月") as XmlElement;
                tbMonth1.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//通知日") as XmlElement;
                tbDay1.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//建筑面积") as XmlElement;
                tbSquares.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//结构层数") as XmlElement;
                tbLevel.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//中标价") as XmlElement;
                tbPrice.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//工期") as XmlElement;
                tbGongqiDay.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//开工年") as XmlElement;
                tbYear2.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//开工月") as XmlElement;
                tbMonth2.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//开工日") as XmlElement;
                tbDay2.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//备注") as XmlElement;
                tbRemark.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//发包单位") as XmlElement;
                tbFaBaoDept.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//备案单位") as XmlElement;
                tbBeiAn.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//法定代表人") as XmlElement;
                tbRepresent.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//经办人") as XmlElement;
                tbJingBan.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//负责人") as XmlElement;
                tbFuze.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//法定年") as XmlElement;
                tbYear3.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//法定月") as XmlElement;
                tbMonth3.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//法定日") as XmlElement;
                tbDay3.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//负责年") as XmlElement;
                tbYear4.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//负责月") as XmlElement;
                tbMonth4.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//负责日") as XmlElement;
                tbDay4.Text = Util.ReturnXml(xe.InnerText);
            
            }
        }

        private string FillContent()
        {
            string template = BLProject.GetTemplate(Provider, "item7.aspx");
            if (template != string.Empty)
            {

                XmlDocument document = new XmlDocument();
                document.LoadXml(template);
                XmlElement xe = document.SelectSingleNode("//施工单位") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbShiGongDept.Text.Trim());               
                xe = document.SelectSingleNode("//工程名称") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbProjectName.Text.Trim());
                xe = document.SelectSingleNode("//通知年") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbYear1.Text.Trim());
                xe = document.SelectSingleNode("//通知月") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbMonth1.Text.Trim());
                xe = document.SelectSingleNode("//通知日") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbDay1.Text.Trim());
                xe = document.SelectSingleNode("//建筑面积") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbSquares.Text.Trim());
                xe = document.SelectSingleNode("//结构层数") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbLevel.Text.Trim());
                xe = document.SelectSingleNode("//中标价") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbPrice.Text.Trim());
                xe = document.SelectSingleNode("//工期") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbGongqiDay.Text.Trim());
                xe = document.SelectSingleNode("//开工年") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbYear2.Text.Trim());
                xe = document.SelectSingleNode("//开工月") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbMonth2.Text.Trim());
                xe = document.SelectSingleNode("//开工日") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbDay2.Text.Trim());
                xe = document.SelectSingleNode("//备注") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbRemark.Text.Trim());
                xe = document.SelectSingleNode("//发包单位") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbFaBaoDept.Text.Trim());
                xe = document.SelectSingleNode("//备案单位") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbBeiAn.Text.Trim());
                xe = document.SelectSingleNode("//法定代表人") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbRepresent.Text.Trim());
                xe = document.SelectSingleNode("//经办人") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbJingBan.Text.Trim());
                xe = document.SelectSingleNode("//负责人") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbFuze.Text.Trim());
                xe = document.SelectSingleNode("//法定年") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbYear3.Text.Trim());
                xe = document.SelectSingleNode("//法定月") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbMonth3.Text.Trim());
                xe = document.SelectSingleNode("//法定日") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbDay3.Text.Trim());
                xe = document.SelectSingleNode("//负责年") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbYear4.Text.Trim());
                xe = document.SelectSingleNode("//负责月") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbMonth4.Text.Trim());
                xe = document.SelectSingleNode("//负责日") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbDay4.Text.Trim());
               
                return document.OuterXml;
            }
            else
                return string.Empty;
           
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            BLProject.SaveProjectItem(Provider, ProjectID, "item7.aspx", FillContent());
           

            string msg = "已保存!";

            string script = "<script>alert('" + msg + "');</script>";
            ClientScript.RegisterStartupScript(this.GetType(), "Close", script);

          
        }
    }
}
